<?php
require_once('ApiConfig.php');

$rate_request_xml_test = <<<XML
<RateRequest>
    <Username>api_user@example.com</Username>
    <Password>yourpassword</Password>
    <Order id="12579">
        <Warehouse>0</Warehouse>
        <AddressInfo type="ship">
            <Address1>321 Foo bar lane</Address1>
            <Address2>Apartment #2</Address2>
            <City>Nowhere</City>
            <State>CA</State>
            <Country>US</Country>
            <Zip>12345</Zip>
        </AddressInfo>
        <Item num="0">
            <Code>12345</Code>
            <Quantity>1</Quantity>
        </Item>
    </Order>
</RateRequest>
XML;

$rate_request_xml = isset($_POST['RateRequestXML']) ? $_POST['RateRequestXML'] : $rate_request_xml_test;

$rate_request = simplexml_load_string($rate_request_xml);

//@todo: Validate rate request and generate rate response.

$rate_response_test_xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE RateResponse SYSTEM "
XML
.BASEURL.
$rate_response_test_xml .= <<<XML
exec/RateResponse.dtd">
<RateResponse>
	<Status>OK</Status>
	<Order sequence="1">
		<Quotes>
			<Quote method="GD">
				<Warehouse>LA (Pick/Pack Saver)</Warehouse>
				<Service>UPS Ground</Service>
				<Cost currency="USD">7.73</Cost>
				<DeliveryEstimate>
					<Minimum units="days">1</Minimum>
					<Maximum units="days">5</Maximum>
				</DeliveryEstimate>
			</Quote>
			<Quote method="2D">
				<Warehouse>LA (Pick/Pack Saver)</Warehouse>
				<Service>UPS Second Day Air</Service>
				<Cost currency="USD">13.64</Cost>
				<DeliveryEstimate>
					<Minimum units="days">2</Minimum>
					<Maximum units="days">2</Maximum>
				</DeliveryEstimate>
			</Quote>
			<Quote method="1D">
				<Warehouse>LA (Pick/Pack Saver)</Warehouse>
				<Service>USPS Express Mail</Service>
				<Cost currency="USD">25.25</Cost>
				<DeliveryEstimate>
					<Minimum units="days">1</Minimum>
					<Maximum units="days">1</Maximum>
				</DeliveryEstimate>
			</Quote>
		</Quotes>
	</Order>
</RateResponse>
XML;

$rate_response_xml = isset($rate_response_xml) ? $rate_response_xml : $rate_response_test_xml;

echo $rate_response_xml;
